/*
 * CPsRecordCaster.h
 *
 *  Created on: 2018年9月1日
 *      Author: zhengboyuan
 */

#ifndef CPSRECORDCASTER_H_
#define CPSRECORDCASTER_H_

#include "PsRecordCaster.h"
#include "RecordStore.h"
#include "SharedPtr.h"
#include "TDiscreteArray.h"
#include "PsRecordCasterChannel.h"


namespace av
{

typedef std::shared_ptr< RecordStore >		RecordStorePtr;

typedef std::shared_ptr< PsRecordCasterChannel >	PsRecordCasterChannelPtr;
typedef comn::DiscreteArray< PsRecordCasterChannelPtr, 1024>	PsRecordCasterChannelArray;



class CPsRecordCaster: public PsRecordCaster, public PsRecordCasterSink
{
public:
	CPsRecordCaster();
	virtual ~CPsRecordCaster();

	virtual bool open(const char* dbpath);

	virtual void close();

	virtual bool isOpen();

	virtual void setEventSink(PsRecordCasterSink* sink);

	virtual int findRecord(const MRecordQuery& query, int offset, MRecord* records, int size);

	virtual int countRecord(const MRecordQuery& query);

	virtual bool getRecord(int id, av::MRecord& record);

	virtual bool deleteRecord(int id);

	virtual int openChannelFile(const PsRecordCasterTransport& transport, MRecord* records, int size, int64_t offset, double scale);

	virtual int openChannelTime(const PsRecordCasterTransport& transport, const char* device, long fromTime, long toTime, double scale);

	virtual void closeChannel(int channel);

	virtual bool addTarget(int channel, const char* ip, int port);

	virtual bool removeTarget(int channel, const char* ip, int port);

	virtual void removeTargets(int channel);

	virtual bool setScale(int channel, double scale);

	virtual bool seek(int channel, int64_t offset);

	virtual bool startCast(int channel);

	virtual void stopCast(int channel);

	virtual void pauseCast(int channel);

protected:
	virtual void onCasterEvent(int channel, int event);

protected:
	RecordStorePtr	m_recordStore;
	PsRecordCasterSink*	m_sink;

	PsRecordCasterChannelArray	m_channels;

};


} /* namespace av */

#endif /* CPSRECORDCASTER_H_ */
